package cn.com.anysdk.starter.config.ocr;

import cn.com.anysdk.ocr.config.OcrProperties;
import cn.com.anysdk.ocr.service.IOcrService;
import cn.com.anysdk.ocr.service.impl.AliyunOcrService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * OCR 服务自动配置
 */
@Configuration
@EnableConfigurationProperties(AliyunOcrProperties.class)
@ConditionalOnProperty(prefix = "anysdk.ocr", name = "enabled", havingValue = "true", matchIfMissing = true)
public class OcrAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(prefix = "anysdk.ocr", name = "provider", havingValue = "aliyun")
    public IOcrService ocrService(OcrProperties properties) {
        return new AliyunOcrService(properties);
    }
}